package com.yckj.day05;

import java.util.Arrays;
import java.util.Random;

/**
 * 模拟斗地主洗牌发牌
 */
public class Cards {
	public static void main(String[] args) {
		String[] cards = {"红桃A,","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K",
				          "黑桃A,","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K",
				          "方块A,","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K",
				          "梅花A,","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8", "梅花9","梅花10","梅花J","梅花Q","梅花K",
				          "大王","小王"
				         };
		//System.out.println(cards.length);
		String[] players = {"范冰冰","李晨","邓超"};
		cards = shuffle(cards);//洗牌
        deal(cards, players);//发牌
	}
	/**
	 * 模拟洗牌
	 * @param cards
	 * @return
	 * @return String[]
	 */
	public static String[] shuffle(String[] cards) {
		Random r = new Random();
		for (int i = cards.length-1; i >= 1; i--) {
			int j = r.nextInt(i);
			String temp = cards[i];
			cards[i] = cards[j];
			cards[j] = temp;		
		}
		System.out.println(Arrays.toString(cards));
		return cards;
	}
	
	/**
	 * 模拟发牌
	 * @param cards
	 * @param players
	 * @return void
	 */
	public static void deal(String[] cards,String[] players) {
		for (int i = 0; i < cards.length; i++) {
			String card = cards[i];
			String someone = players[i % 3];//三个人中的某个人
			System.out.println(someone+":"+card);
		}
	}

}
